package com.sc.web.gwt.server.service;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.sc.web.gwt.client.service.AgentAdminDataManagementService;
import com.sc.web.gwt.server.persistence.AgentAdminPersistence;
import com.sc.web.gwt.shared.model.AgentAdmin;

import java.util.List;

public class AgentAdminDataManagementServiceImpl extends RemoteServiceServlet implements AgentAdminDataManagementService {
    AgentAdminPersistence agentAdminPersistence = new AgentAdminPersistence();

    public List<AgentAdmin> getAllAgentAdmins() {
        return agentAdminPersistence.getAllAgentAdmins();
    }

    public List<AgentAdmin> searchAgentAdmins(String searchText, int selectedIndex) {
        return agentAdminPersistence.searchAgentAdmins(searchText, selectedIndex);
    }

    public boolean saveOrUpdateAgentAdminData(AgentAdmin agentAdmin) {
        if (agentAdmin.getAgentAdminId() != -1)
            return agentAdminPersistence.updateAgentAdmin(agentAdmin);
        else {
            return agentAdminPersistence.insertAgentAdmin(agentAdmin);
        }
    }

    public AgentAdmin getAgentAdminInfo() {
        AgentAdmin result = agentAdminPersistence.getAgentAdmin(Integer.parseInt(getThreadLocalRequest().getSession().getAttribute("userId").toString()));

        return result;
    }

}